let arr = ["I", "go", "home"];

delete arr[1];

alert(arr[1]);

alert(arr.length);


// 使用delete能够删除数组元素，但是不能修改数组的元素位置，即上例中删除了第二个元素go，但是数组的长度还是3，原来第二个位置的地方值现在是undefined

let arr2 = ["I", "study", "JavaScript"];

arr.splice(1, 1);       // 从索引1开始删除1各元素

alert(arr2);

let arr3 = ["I", "study", "JavaScript", "right", "now"];

arr3.splice(0, 3, "Let's ", "dance");

alert(arr3);

let removed = arr3.splice(0, 2);

alert(removed);


//将deleteCount设置为0，则splice方法就可以插入元素而不用删除任何元素
let arr4 = ["I", "study", "JavaScript"];

arr4.splice(2, 0, "complex", "language");

alert(arr4);